#include "mybutton.h"
#include <QPainter>
#include <QMouseEvent>

MyButton::MyButton(QWidget *parent) :
    QWidget(parent)
{
}

void MyButton::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    // 创建一个画家
    QPainter painter(this);
    // 抗锯齿，变得更光滑
    painter.setRenderHint(QPainter::Antialiasing, true);
    // 设置画笔(画轮廓的)为透明，去掉边框
    painter.setPen(Qt::transparent);
    // 绘制按钮样式
    painter.setBrush(m_color);  // 画刷，填充区域颜色的
    painter.drawRoundedRect(this->rect(), height()/6, height()/6);
//    painter.drawRect(this->rect());
    painter.setFont(QFont("宋体",m_fontSize));
    // 重新设置画笔轮廓颜色，作为文字的颜色
    painter.setPen(Qt::white);
    painter.drawText(this->rect(), Qt::AlignCenter, m_text);

}

void MyButton::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        // 处理鼠标左键点击事件
        emit clicked();
    }
}
